package com.um.jdy.common.finance.service.impl;

import cn.hutool.core.date.DateUtil;
import com.um.jdy.common.finance.enums.FinancialEnum;
import com.um.springboot.starter.utils.OrderUtil;

import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import com.um.springboot.starter.orm.service.BaseEntityServiceImpl;
import com.um.jdy.common.finance.service.UserBillService;
import com.um.jdy.common.finance.dao.UserBillDao;
import com.um.jdy.common.finance.entity.po.UserBill;

/**
 * 服务实现类：用户流水表
 */
@Service
@Slf4j
public class UserBillServiceImpl extends BaseEntityServiceImpl<UserBillDao,UserBill>  implements UserBillService{

    @Override
    public UserBill addBill(String comId, String memberUserId, String outTradeNo, String orderNo, Integer amount,
                            FinancialEnum.IncomeOrExpend type, FinancialEnum.UserBillEvent event, FinancialEnum.BillStatus status) {

        UserBill bill = new UserBill();
        bill.setComId(comId);
        bill.setMemberUserId(memberUserId);
        bill.setNo(OrderUtil.getOrderNo());
        bill.setOutTradeNo(outTradeNo);
        bill.setOrderNo(orderNo);
        bill.setAmount(amount);
        bill.setType(type.name());//收入支出类型：0-收入，1-支出
        bill.setEvent(event.name());
        bill.setStatus(status.name());//账单状态：0未生效|1已生效|2已失效
        bill.setCreateTime(DateUtil.date());
        saveRow(bill);

        return bill;
    }
}
